//
//  MainWindowDelegate.m
//  XPComDemo
//
//  Created by Junjie Gong on 12-5-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MainWindowDelegate.h"
#include "ToolbarCallbackDecorator.h"

@implementation MainWindowDelegate

@synthesize callbackDecorator;

- (id)init{
    if (self=[super init]) {

    }
    return self;
}

- (void)showTooptips{
    [self performSelector:@selector(showTooptips1) withObject:nil afterDelay:(1)];
     NSLog(@"showTooptips end");

}

- (void)showTooptips1{
    if (statusWindow) {
        return;
    }
    
    ToolbarCallbackDecorator *callback = (ToolbarCallbackDecorator *)callbackDecorator;
    
    NSWindow *wx = (NSWindow *)callback->GetBrowserWindow();
    
    oldPoint = wx.frame.origin;
    
    NSWindow *w = [[NSWindow alloc] initWithContentRect:
                   NSMakeRect(oldPoint.x+100, oldPoint.y+100, 300, 300) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
    { 
        [w setAlphaValue:0.90];
        [w setOpaque:NO];
        [w setBackgroundColor:[NSColor redColor]];
        [w setHasShadow:YES];
        [w setLevel:NSStatusWindowLevel];
        [w setHidesOnDeactivate:YES];
        //[w setIgnoresMouseEvents:YES];
    }
    NSButton *bt = [[NSButton alloc] initWithFrame:NSMakeRect(30, 30, 60, 40)];
    [bt setTitle:@"Close"];
    [bt setTarget:self];
    [bt setAction:@selector(closeWindow:)];
    [[w contentView] addSubview:bt];
    [bt release];
    
    [w orderFront:nil];
    [wx addChildWindow:w ordered:NSWindowAbove];
    statusWindow = w;
}


- (IBAction)closeWindow:(id)sender{
    ToolbarCallbackDecorator *callback = (ToolbarCallbackDecorator *)callbackDecorator;
    NSWindow *wx = (NSWindow *)callback->GetBrowserWindow();
    [wx removeChildWindow:statusWindow];
    [statusWindow close];
    [statusWindow autorelease];
    statusWindow = nil;
}
         
         
- (NSPoint)getWindowPoint:(NSWindow *)w{
    return [[w screen] frame].origin;
}

@end

 
